package edu.cmu.javadb.plan;


import java.util.*;

import edu.cmu.javadb.plan.visitor.Visitor;

public class Union extends PlanNode {
	private List<PlanNode> children = new ArrayList<PlanNode>();

	@Override
	public <T> T accept(Visitor<T> visitor) {
		return visitor.visitNode(this);
	}

	public void addChildren(PlanNode child) {
		children.add(child);
		child.setFather(this);
	}

	public List<PlanNode> getChildren() {
		return children;
	}

	public void setChildren(List<PlanNode> children) {
		this.children = children;
		for (PlanNode child : children) {
			child.setFather(this);
		}
	}

	@Override
	public String toString() {
		return "Union[" + this.getName() + "]";
	}

	@Override
	public <T> void visitChildren(Visitor<T> visitor) {
		for (PlanNode node : children) {
			node.accept(visitor);
		}
	}

	@Override
	public boolean containsRelation(String name) {
		if (this.name.equals(name))
			return true;
		for (PlanNode node : children) {
			if (node.containsRelation(name)) {
				return true;
			}
		}
		return false;
	}
}
